package com.chixing.day17_reflect_thread;



public class Account {
    private String accName;
    private double accBalance;

    public Account(String accName, double accBalance) {
        this.accName = accName;
        this.accBalance = accBalance;
    }

    //存款
    //synchronized : 当前线程 拥有该account 对象的锁
    public synchronized double depoist(double money){
        //模拟实际生活中 存款需要消耗的时间
        double temp = this.accBalance;
        temp += money;
        try {
            Thread.sleep(2);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        this.accBalance = temp;
        System.out.println(Thread.currentThread().getName() + ":当前账余额是: " + this.accBalance);
        return this.accBalance;
    }

    public String getAccName() {
        return accName;
    }

    public void setAccName(String accName) {
        this.accName = accName;
    }

    public double getAccBalance() {
        return accBalance;
    }

    public void setAccBalance(double accBalance) {
        this.accBalance = accBalance;
    }

    @Override
    public String toString() {
        return "Account{" +
                "accName='" + accName + '\'' +
                ", accBalance=" + accBalance +
                '}';
    }


}
